﻿using System;
using System.Data;
using System.Xml.Linq;

namespace YArchitech.Temp
{
	public class HYMaterial : HYPipeSpecifications, IComparable, IHYXmlSerial
	{
		public PipeType Type { get; set; }

		public int Id { get; set; }

		public string Name { get; set; }

		public string Unit { get; set; }

		public string Mark { get; set; }

		public string Symbol { get; set; }

		public double K { get; set; }

		public double Density { get; set; }

		public string Comment { get; set; }

		public string PARAM1 { get; set; }

		public string PARAM2 { get; set; }

		public string PARAM3 { get; set; }

		public HYMaterial()
		{
			this.Type = PipeType.Pipe;
			this.Id = -1;
			this.Name = "";
			this.Unit = "";
			this.Mark = "";
			this.Symbol = "";
			this.K = 0.0;
			this.Density = 0.0;
			this.Comment = "";
			this.PARAM1 = "";
			this.PARAM2 = "";
			this.PARAM3 = "";
		}

		public int CompareTo(object obj)
		{
			if (obj is HYMaterial)
			{
				HYMaterial hymaterial = obj as HYMaterial;
				return this.Name.CompareTo(hymaterial.Name);
			}
			return 1;
		}

		public override void WriteXml(XElement xe)
		{
			xe.SetAttributeValue("Id", this.Id);
			xe.SetAttributeValue("Type", (int)this.Type);
			xe.SetAttributeValue("Name", this.Name);
			xe.SetAttributeValue("Unit", this.Unit);
			xe.SetAttributeValue("Mark", this.Mark);
			xe.SetAttributeValue("Symbol", this.Symbol);
			xe.SetAttributeValue("K", this.K);
			xe.SetAttributeValue("Density", this.Density);
			xe.SetAttributeValue("Comment", this.Comment);
			xe.SetAttributeValue("PARAM1", this.PARAM1);
			xe.SetAttributeValue("PARAM2", this.PARAM2);
			xe.SetAttributeValue("PARAM3", this.PARAM3);
			base.WriteXml(xe);
		}

		public override void ReadXml(XElement xe)
		{
			this.Id = (int)xe.Attribute("Id");
			int type = (int)xe.Attribute("Type");
			this.Type = (PipeType)type;
			this.Name = xe.Attribute("Name").Value;
			this.Unit = xe.Attribute("Unit").Value;
			this.Mark = xe.Attribute("Mark").Value;
			this.Symbol = xe.Attribute("Symbol").Value;
			this.K = (double)xe.Attribute("K");
			this.Density = (double)xe.Attribute("Density");
			this.Comment = xe.Attribute("Comment").Value;
			this.PARAM1 = xe.Attribute("PARAM1").Value;
			this.PARAM2 = xe.Attribute("PARAM2").Value;
			this.PARAM3 = xe.Attribute("PARAM3").Value;
			base.ReadXml(xe);
		}

		private bool ReadData(DataRow row)
		{
			if (row == null)
			{
				return false;
			}
			int num = -1;
			if (!int.TryParse(row["ID"].ToString(), out num))
			{
				return false;
			}
			this.Type = (PipeType)Enum.Parse(typeof(PipeType), row["Type"].ToString());
			this.Name = row["Name"].ToString();
			this.Unit = row["Unit"].ToString();
			this.Mark = row["Mark"].ToString();
			this.Symbol = row["Symbol"].ToString();
			double k = 0.0;
			if (double.TryParse(row["K"].ToString(), out k))
			{
				this.K = k;
			}
			double density = 0.0;
			if (double.TryParse(row["Density"].ToString(), out density))
			{
				this.Density = density;
			}
			this.Comment = row["Comment"].ToString();
			this.PARAM1 = row["PARAM1"].ToString();
			this.PARAM2 = row["PARAM2"].ToString();
			this.PARAM3 = row["PARAM3"].ToString();
			return true;
		}
	}
}
